﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using BathhouseService.Models.SqlModels;
using BathhouseService.Models.Commonality;
using Microsoft.EntityFrameworkCore;

namespace BathhouseService.CURD.ViewModels.PaymentRecordVMs
{
    public partial class PaymentRecordVM : BaseCRUDVM<PaymentRecord>
    {
        public List<ComboSelectListItem> AllPayWays { get; set; }
        public List<ComboSelectListItem> AllValueAddedServicess { get; set; }
        public List<ComboSelectListItem> AllCustomer { get; set; }
        public List<ComboSelectListItem> AllServicePerson { get; set; }

        public PaymentRecordVM()
        {
            SetInclude(x => x.PayWay);
            SetInclude(x => x.ValueAddedServices);
        }

        protected override void InitVM()
        {
            AllPayWays = DC.Set<PayWay>().GetSelectListItems(LoginUserInfo?.DataPrivileges, null, y => y.Names);
            AllValueAddedServicess = DC.Set<ValueAddedServices>().GetSelectListItems(LoginUserInfo?.DataPrivileges, null, y => y.Names);
            AllCustomer = DC.Set<FrameworkUserBase>().GetSelectListItems(LoginUserInfo?.DataPrivileges, null, y => y.Name);
            AllServicePerson = DC.Set<FrameworkUserBase>().GetSelectListItems(LoginUserInfo?.DataPrivileges, null, y => y.Name);
        }

        public override void DoAdd()
        {
            int count = DC.Set<PaymentRecord>().Count();

            Entity.OrderId = AutomaticNumbering.GetNumber(count, "DC.");
            Entity.PaymentTime = DateTime.Now;
            Entity.CustomerName = DC.Set<FrameworkUserBase>().SingleOrDefault(x => x.ID == Entity.CustomerId).Name;
            Entity.ServicePersonName = DC.Set<FrameworkUserBase>().SingleOrDefault(x => x.ID == Entity.ServicePersonId).Name;


            base.DoAdd();
        }

        public override void DoEdit(bool updateAllFields = false)
        {
            base.DoEdit(updateAllFields);
        }

        public override void DoDelete()
        {
            base.DoDelete();
        }
    }
}
